<template>
  <div style="width:100px;">
    <el-input type="text" v-model="loginForm.account" placeholder="用户名"/>
    <el-input type="text" v-model="loginForm.password" placeholder="密码"/>
    <el-button @click="login">登录</el-button>
  </div>
</template>

<script>

export default {
  data () {
    return {
      loginForm: {
        account: '',
        password: ''
      }
    };
  },
 
  methods: {
    login () {
      let _this = this;
      if (this.loginForm.account === '' || this.loginForm.password === '') {
        alert('账号或密码不能为空');
      } else {
        this.axios({
          method: 'post',
          url: 'http://localhost:8080/login/account',
          data: _this.loginForm
        }).then(res => {
          console.log(res.data);
        //   _this.userToken = 'Bearer ' + res.data.data.body.token;
          // 将用户token保存到vuex中
          _this.$router.push('/user');
          alert('登陆成功');
        }).catch(error => {
          alert('账号或密码错误');
          console.log(error);
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>


</style>